<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <table>
        <thead>
            <tr>
                <th>姓名</th>
                <th>科目</th>
                <th>成绩</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>
    <script>
        //准备数据
        var datas = [{
                name: 'xqz',
                subject: 'javascript',
                score: 100
            },
            {
                name: 'xqz',
                subject: 'javascript',
                score: 100
            },
            {
                name: 'xqz',
                subject: 'javascript',
                score: 100
            },
            {
                name: 'xqz',
                subject: 'javascript',
                score: 100
            }
        ];
        //往tbody里面创建行
        var tbody = document.querySelector('tbody');
        for (let i = 0; i < datas.length; i++) {
            var tr = document.createElement('tr');
            tbody.appendChild(tr);
            //创建单元格td 数量取决于每个对象里的属性个数
            for (var k in datas[i]) {
                var td = document.createElement('td');
                //把属性值给td
                td.innerHTML = datas[i][k];
                tr.appendChild(td);
            }
            // 创建删除的单元格
            var td = document.createElement('td');
            td.innerHTML = '<a href="javascript:;">删除</a>';
            tr.appendChild(td);
        }
        //删除操作
        var as = document.querySelectorAll('a');
        var trs = document.querySelectorAll('tr');
        for (var i = 0; i < as.length; i++) {
            as[i].onclick = function () {
                tbody.removeChild(this.parentNode.parentNode);
            }
        }
    </script>
</body>

</html>